package com.itestor.iptv.modules.common.utils;

import java.security.MessageDigest;

public class SecureUtils {

	public static String MD5Encrypt(String source) {
		if (source == null) {
			return null;
		}
		String resultString = null;
		try {
			resultString = new String(source);
			MessageDigest md = MessageDigest.getInstance("MD5");
			resultString = byte2hexString(md.digest(resultString.getBytes()));
		} catch (Exception ex) {
		}
		return resultString;
	}

	public static final String byte2hexString(byte bytes[]) {
		StringBuffer buf = new StringBuffer(bytes.length * 2);
		for (int i = 0; i < bytes.length; i++) {
			if ((bytes[i] & 0xff) < 16)
				buf.append("0");
			buf.append(Long.toString(bytes[i] & 0xff, 16));
		}
		return buf.toString();
	}

}